package com.example.transaction.state.impl;

import com.example.transaction.common.enums.StepStateEnum;
import com.example.transaction.entity.Step;
import com.example.transaction.service.common.IStepCommonService;
import com.example.transaction.state.IStepState;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class StepStartState implements IStepState {

    @Autowired
    private IStepCommonService stepCommonService;
    @Override
    public StepStateEnum getState() {
        return StepStateEnum.START;
    }

    @Override
    public void finish(Step step) {
        stepCommonService.lambdaUpdate().eq(Step::getStepId, step.getStepId())
                .eq(Step::getState, step.getState())
                .set(Step::getState, StepStateEnum.FINISH_REVIEW.getCode())
                .update();
    }

    @Override
    public void skip(Step step) {
        stepCommonService.lambdaUpdate().eq(Step::getStepId, step.getStepId())
                .eq(Step::getState, step.getState())
                .set(Step::getState, StepStateEnum.SKIP_REVIEW.getCode())
                .update();
        log.info("状态变更为跳过待复核");
    }

    @Override
    public void fail(Step step) {
        stepCommonService.lambdaUpdate().eq(Step::getStepId, step.getStepId())
                .eq(Step::getState, step.getState())
                .set(Step::getState, StepStateEnum.FAIL_REVIEW.getCode())
                .update();
    }
}
